var $parentNode = window.parent.document;

function $childNode(name) {
    return window.frames[name]
}

// tooltips
$('.tooltip-demo').tooltip({
    selector: "[data-toggle=tooltip]",
    container: "body"
});

// 使用animation.css修改Bootstrap Modal
$('.modal').appendTo("body");

$("[data-toggle=popover]").popover();

//折叠ibox
$('.collapse-link').click(function () {
    var ibox = $(this).closest('div.ibox');
    var button = $(this).find('i');
    var content = ibox.find('div.ibox-content');
    content.slideToggle(200);
    button.toggleClass('fa-chevron-up').toggleClass('fa-chevron-down');
    ibox.toggleClass('').toggleClass('border-bottom');
    setTimeout(function () {
        ibox.resize();
        ibox.find('[id^=map-]').resize();
    }, 50);
});

//关闭ibox
$('.close-link').click(function () {
    var content = $(this).closest('div.ibox');
    content.remove();
});

//判断当前页面是否在iframe中
//if (top == this) {
//    var gohome = '<div class="gohome"><a class="animated bounceInUp" href="index.html?v=4.0" title="返回首页"><i class="fa fa-home"></i></a></div>';
//    $('body').append(gohome);
//}

//animation.css
function animationHover(element, animation) {
    element = $(element);
    element.hover(
        function () {
            element.addClass('animated ' + animation);
        },
        function () {
            //动画完成之前移除class
            window.setTimeout(function () {
                element.removeClass('animated ' + animation);
            }, 2000);
        });
}

//拖动面板
function WinMove() {
    var element = "[class*=col]";
    var handle = ".ibox-title";
    var connect = "[class*=col]";
    $(element).sortable({
            handle: handle,
            connectWith: connect,
            tolerance: 'pointer',
            forcePlaceholderSize: true,
            opacity: 0.8,
        })
        .disableSelection();
};


//编辑器新增的ajax上传图片函数
function sendFile(files, editor, $editable) {
    var size = files[0].size;
    if((size / 1024 / 1024) > 2) {
        alert("图片大小不能超过2M...");
        return false;
    }
    console.log("size="+size);
    var formData = new FormData();
    formData.append("file", files[0]);
    $.ajax({
        data : formData,
        type : "POST",
        url : "/common/sysFile/upload",    // 图片上传出来的url，返回的是图片上传后的路径，http格式
        cache : false,
        contentType : false,
        processData : false,
        dataType : "json",
        success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名
            $('.summernote').summernote('insertImage',data.fileName);
        },
        error:function(){
            alert("上传失败");
        }
    });
}

/**
 * 文本框回车触发事件的方法
 */
function getKey(){
    if(event.keyCode==13){
    	reLoad();
    }   
}

/**
 * 重置
 */
function refresh(){
	$(".fixed-table-toolbar").find("input").val("");
	$(".fixed-table-toolbar").find("select").val("");
	$('#exampleTable').bootstrapTable('refresh');
}

//用于整数及小数校验
var point = false;
/**
 * 正数验证，并且保留小数点位数
 */
function checkNum(obj1,obj2,checkmess,num) { 
	//obj1:输入框中的内容；obj2：提示信息span标签id；checkmess：提示信息内容；num：小数点后位数
	var check = obj2;
	var bit = num;
	//验证输入内容是否为正数，并显示提示信息
	getCheckNumMess(obj1,check,checkmess);
	//去掉输入的空格
    if(!$.trim(obj1.value)) {
    	obj1.value = "";  
    }
    if (obj1 != null) {
    	//去掉输入的空格
    	obj1.value=$.trim(obj1.value);
    	if(bit=="0"){
   		 	//检查是否是整数
	        if (obj1.value.toString().split(".").length > 1) {
	         point = true;
		     getCheckNumMess(obj1,check,checkmess);
	       	 var aNew = obj1.value.substring(0,obj1.value.indexOf("."));
	       	 obj1.value = aNew; 
	        }
    	}else if(bit=="2"){
	        //检查小数点后是否是两位
	        if (obj1.value.toString().split(".").length > 1 && obj1.value.toString().split(".")[1].length > 2) {
	         point = true;
			 getCheckNumMess(obj1,check,checkmess);
	       	 var re = /([0-9]+\.[0-9]{2})[0-9]*/;
	       	 var aNew = obj1.value.replace(re,"$1");
	       	 obj1.value = aNew;  
	        }
    	}else if(bit=="4"){
    		 //检查小数点后是否是四位
	        if (obj1.value.toString().split(".").length > 1 && obj1.value.toString().split(".")[1].length > 4) { 
	         point = true;
			 getCheckNumMess(obj1,check,checkmess);
	       	 var re = /([0-9]+\.[0-9]{4})[0-9]*/;
	       	 var aNew = obj1.value.replace(re,"$1");
	       	 obj1.value = aNew;  
	        }
    	}else if(bit=="6"){
    		 //检查小数点后是否是六位
	        if (obj1.value.toString().split(".").length > 1 && obj1.value.toString().split(".")[1].length > 6) {
	         point = true;
			 getCheckNumMess(obj1,check,checkmess);
	       	 var re = /([0-9]+\.[0-9]{6})[0-9]*/;
	       	 var aNew = obj1.value.replace(re,"$1");
	       	 obj1.value = aNew;  
	        }
    	}else if(bit=="1"){
   		 //检查小数点后是否是一位
	         if (obj1.value.toString().split(".").length > 1 && obj1.value.toString().split(".")[1].length > 0) {  
	       	 var re = /([0-9]+\.[0-9]{1})[0-9]*/;
	       	 var aNew = obj1.value.replace(re,"$1");
	       	 obj1.value = aNew;  
	        }
    	}
    }  
}
//数字校验时的提示信息
function getCheckNumMess(obj1,check,checkmess){
	if (isNaN(obj1.value)||(obj1.value)<0||point) {
  		 $("#"+check).html("<font color=\"red\">"+checkmess+"</font>");
  		 // 计时器：提示文字3秒后消失
  	  var i = 3;
   	  setInterval(function(){               
           if(i == 0) {
           	$("#"+check).html("");
           }
           i--;
        },1000);
   	   if(!point){
   		obj1.value = ""; 
   	   }
       point = false;
   }
}

var dictname="";
var dicts ="";
function getDictByType(type){
	var aa="";
	$.ajax({
		url : "/common/dict/listTypeOrderBySort",
		type : "GET",
		cache: false,
        async : false,
        dataType: "json",
		data : {
			'type' : type
		},
		success : function(result) {
			aa=result;
			return aa;
		}
	});
	return aa;
}
/**
 * 
 * 获取当前时间
 */
function p(s) {
    return s < 10 ? '0' + s: s;
}
//Oss图片服务器路径
var Oss_Url="http://aleiaapi.oss-cn-qingdao.aliyuncs.com/";

(function($){
	  $.fn.autoTextarea = function(options) {
	    var defaults={
	      maxHeight:null,
	      minHeight:$(this).height()
	    };
	    var opts = $.extend({},defaults,options);
	    return $(this).each(function() {
	      $(this).bind("paste cut keydown keyup focus blur",function(){
	        var height,style=this.style;
	        this.style.height = opts.minHeight + 'px';
	        if (this.scrollHeight > opts.minHeight) {
	          if (opts.maxHeight && this.scrollHeight > opts.maxHeight) {
	            height = opts.maxHeight;
	            style.overflowY = 'scroll';
	          } else {
	            height = this.scrollHeight;
	            style.overflowY = 'hidden';
	          }
	          style.height = height + 'px';
	        }
	      });
	    });
	  };
})(jQuery);
